﻿namespace PillBox.Client
{
    using System;
    using System.Windows;
    using PillBox.Client.Framework;

    public partial class App : Application
    {
        public App()
        {
            this.UnhandledException += Application_UnhandledException;
            this.Startup += Application_Startup;

            Properties.Resources.Culture = System.Threading.Thread.CurrentThread.CurrentCulture;

            InitializeComponent();
        }

        private void Application_Startup(object sender, StartupEventArgs e)
        {
            this.RootVisual = Bootstrapper.CreateShell();
        }

        // Code to execute on Unhandled Exceptions
        private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)
        {
            if (System.Diagnostics.Debugger.IsAttached)
            {
                // An unhandled exception has occurred, break into the debugger
                System.Diagnostics.Debugger.Break();
            }
            else
            {
                // By default show the error
                e.Handled = true;
                MessageBox.Show(
                    e.ExceptionObject.Message + Environment.NewLine + e.ExceptionObject.StackTrace,
                    "Error",
                    MessageBoxButton.OK);
            }
        }
    }
}